﻿namespace PowerSong.UserInterface
    {
    using System;
    using System.Text;

    public class RawReport : Report
        {

        public string ReportContents { get; private set; }

        private DateTime startDate;

        private DateTime endDate;

        public RawReport(DateTime startDate, DateTime endDate)
            {
            this.startDate = startDate;
            this.endDate = endDate;
            }

        public override void Execute()
            {

            // Start from the start date
            var text = new StringBuilder();

            // Process all applicable log events
            foreach (var entry in State.Database.ActivityLog.Get(startDate, endDate))
                {

                // Write the log data
                text.Append(entry.Time.ToShortDateString()).Append(" ").Append(entry.Time.ToShortTimeString());
                text.Append(", ").Append(entry.Type).Append(" ").Append(entry.ActionPerformed);
                var song = State.Database.Songs.Get(entry.ItemID);
                var title = song == null ? "Unknown Item" : song.Title;
                text.Append(", \"").Append(title).AppendLine("\"");

                }

            this.ReportContents = text.ToString();

            }

        }

    }